// JavaScript Document
function CloseLoginFirstForm(){
		TweenLite.to($("#loginFirstBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#loginFirstBox"), 0, {css:{display:"none"}});
		}});

}

function CloseLoginFrom(){
		TweenLite.to($("#brushBlack"), 0.5, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#brushBlack"), 0, {css:{display:"none"}});
		}});
		TweenLite.to($("#collectBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#collectBox"), 0, {css:{display:"none"}});
		}});
		TweenLite.to($("#editCollectBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#editCollectBox"), 0, {css:{display:"none"}});
		}});
		TweenLite.to($("#editUserInfoBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#editUserInfoBox"), 0, {css:{display:"none"}});
		}});
		TweenLite.to($("#loginBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#loginBox"), 0, {css:{display:"none"}});
		}});

		TweenLite.to($("#loginFirstBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#loginFirstBox"), 0, {css:{display:"none"}});
		}});

		TweenLite.to($("#uploadIdeaBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#uploadIdeaBox"), 0, {css:{display:"none"}});
		}});

		TweenLite.to($("#logInTitle a"), 0.5, {css:{left:0},ease:Quint.easeOut});
		TweenLite.to($("#enterForm"), 0.5, {css:{left:0},ease:Quint.easeOut});
		TweenLite.to($("#forgetForm"), 0.5, {css:{left:300},ease:Quint.easeOut});
	}
function initialLoginForm(){

		$(".btn_cancel a").click(function(e){
			CloseLoginFrom();
			e.preventDefault();
		});
		$(".btnClose").click(function(e){
			CloseLoginFrom();
			e.preventDefault();
		});

		$(".register_btn_cancel a").click(function(e){
			CloseLoginFrom();
			e.preventDefault();
		});

		$(".register_link").click(function(e){
			e.preventDefault();
			$.ajax({
				url: '/houseme/showRegisterForm',
				type:"POST",
				dataType:"json",
				data:{
					
				},
				success: function(data)
				{	
					$('#loginBox').html(data.html);
					initialLoginForm();
				}
			});
		});

		$(".forgot_password_link").click(function(e){
			e.preventDefault();
			$.ajax({
				url: '/houseme/showForgotPasswordForm',
				type:"POST",
				dataType:"json",
				data:{
					
				},
				success: function(data)
				{	
					$('#loginBox').html(data.html);
					initialLoginForm();
				}
			});
		});
		/*login*/
		$('.btn_login_send').click(function(event){
			event.preventDefault();
			var temp = $('#loginBox').html();
			
			$.ajax({
				url: '/auth/fe_login',
				type:"POST",
				dataType:"json",
				data:{
					login: $('#email_login').val(),
					password: $('#password_login').val()
				},
				beforeSend:function(){
					
					$('#loginBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){ // error occurred
						//alert(data.msg);
						$('#loginBox').html(data.html);
						initialLoginForm();
					}
					else if(data.status_code == '1'){
						if(data.goto_page != null){
							window.location = data.goto_page;
						}
						else if(data.page_action_event_element != null){
							CloseLoginFrom();
							console.log(data.page_action_event_element);
							$(data.page_action_event_element)[0].click();
						}
						else{
							location.reload();	
						}
					}
					else if(data.status_code == '3'){
						alert(data.msg);
					}
					 
				}
			});
			
		});

		/*send again*/
		$('.btn_login_send_again').click(function(event){
			event.preventDefault();
			var temp = $('#loginBox').html();
			
			$.ajax({
				url: '/auth/fe_send_again',
				type:"POST",
				dataType:"json",
				data:{
					email: $('#email_login').val()
				},
				beforeSend:function(){
					
					$('#loginBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){ // error occurred
						//alert(data.msg);
						$('#loginBox').html(data.html);
						initialLoginForm();
					}
					else if(data.status_code == '1'){
						location.reload();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
						location.reload();
					}
					 
				}
			});
			
		});

		/*forgot password*/
		$('.btn_forgot_password_send').click(function(event){
			event.preventDefault();
			var temp = $('#loginBox').html();
			
			$.ajax({
				url: '/auth/fe_forgot_password',
				type:"POST",
				dataType:"json",
				data:{
					login: $('#email_login').val()
				},
				beforeSend:function(){
					
					$('#loginBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){ // error occurred
						//alert(data.msg);
						$('#loginBox').html(data.html);
						initialLoginForm();
					}
					else if(data.status_code == '1'){
						location.reload();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
						location.reload();
					}
					 
				}
			});
			
		});

		$('.register_btn_send').click(function(event){
			event.preventDefault();
			var temp = $('#loginBox').html();
			
			$.ajax({
				url: '/auth/fe_register',
				type:"POST",
				dataType:"json",
				data:{
					username: $('#username_register').val(),
					email: $('#email_register').val(),
					password: $('#password_register').val(),
					confirm_password: $('#confirm_password_register').val()
				},
				beforeSend:function(){
					
					$('#loginBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){
						$('#loginBox').html(data.html);
						initialLoginForm();
					}
					else if(data.status_code == '1'){
						alert(data.msg);
						CloseLoginFrom();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
					}
					 
				}
			});
		});
}
function showLoginBox(){
		TweenLite.to($("#loginBox"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#loginBox"), 0.5, {alpha:1,ease:Quint.easeOut});
		}});
		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
		}});
	}
function showLoginFirstBox(){
		TweenLite.to($("#loginFirstBox"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#loginFirstBox"), 0.5, {alpha:1,ease:Quint.easeOut});
		}});
		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
		}});
	}

function voteThis(question_id,vote_id){
	var r = confirm("確定投下這票嗎？");
	if (r == true) {
		$.ajax({
			url: '/question/vote',
			type:"POST",
			dataType:"json",
			data:{
				id: vote_id,
				question_id: question_id,
			},
			success: function(data)
			{	
				if(data.status_code == '1')
				{
					$('#votebar_'+vote_id).width(data.vote_counts+'%');
					$('#votenum_'+vote_id).html(data.vote_counts+'票');
				}else if(data.status_code == '2'){
					alert(data.msg);
				}
				else if(data.status_code == '4'){
					$.ajax({
						url: '/houseme/showLoginFirstForm',
						type:"POST",
						dataType:"json",
						data:{
							
						},
						success: function(data)
						{	
							$('#loginFirstBox').html(data.html);
							showLoginFirstBox();
							$(".logBtnEmail").click(function(e){
								e.preventDefault();
								CloseLoginFirstForm();
								$.ajax({
									url: '/houseme/showLoginForm',
									type:"POST",
									dataType:"json",
									data:{
										
									},
									success: function(data)
									{	
										$('#loginBox').html(data.html);
										showLoginBox();
										initialLoginForm();
									}
									});
							});
						}
					});
				}
			}
		});
	}

	return false;
}

function initialAjaxQuestionForm(){

	var r = confirm("確定送出？");
	if (r == true) {
	    var temp;
		var options = { 
	        beforeSubmit:  function(){
	        	$("#submit_question").removeAttr("onclick");
	        	$('#submit_question').html('<img src="/assets/img/input-spinner.gif" style="width:20px;height:20px;"/>');
	        },
	        dataType:  'json',
	        success:  function(data){
	        	if(data.status_code == '2'){
					alert(data.msg);
				}
				else if(data.status_code == '1'){ // upload success
					alert(data.msg);
					location.reload();
				}
				else if(data.status_code == '3'){// form error
					alert(data.msg);
					$('#submit_question').html('發 表 提 問');
					$('#submit_question').click(function(){initialAjaxQuestionForm();$('#questionForm').submit();});
				}
				else if(data.status_code == '4'){// login first
					$('#submit_question').html('發 表 提 問');
					$('#submit_question').click(function(){initialAjaxQuestionForm();$('#questionForm').submit();});

					$.ajax({
						url: '/houseme/showLoginFirstForm',
						type:"POST",
						dataType:"json",
						data:{
							
						},
						success: function(data)
						{	
							$('#loginFirstBox').html(data.html);
							showLoginFirstBox();
							$(".logBtnEmail").click(function(e){
								e.preventDefault();
								CloseLoginFirstForm();
								$.ajax({
									url: '/houseme/showLoginForm',
									type:"POST",
									dataType:"json",
									data:{
										
									},
									success: function(data)
									{	
										$('#loginBox').html(data.html);
										showLoginBox();
										initialLoginForm();
									}
									});
							});
						}
					});
				}
	        }  
	    }; 
	 
	    // bind form using 'ajaxForm' 
	    $('#questionForm').ajaxForm(options); 
	    $('#questionForm').submit();
	}

    return;
}

function initialAjaxCommentForm(){

	var r = confirm("確定送出？");
	if (r == true) {
	    var temp;
		var options = { 
	        beforeSubmit:  function(){
	        	$("#submit_comment").removeAttr("onclick");
	        	$('#submit_comment').html('送出中...');
	        },
	        dataType:  'json',
	        success:  function(data){
	        	if(data.status_code == '2'){
					alert(data.msg);
				}
				else if(data.status_code == '1'){ // upload success
					var html = data.new_comment_html;
					
					$('#comment').val('');
					$('#votePhotosArea').html('');
					$('#comment_area').append($(html).hide().fadeIn(2000));
					$('#submit_comment').html('留下意見');
					$('#submit_comment').click(function(){initialAjaxCommentForm();$('#commentForm').submit();});

					// initial fancybox image again

					$("a.thumb_images").fancybox({
			            'titleShow'     : false
			        });
				}
				else if(data.status_code == '3'){// form error
					alert(data.msg);
					$('#submit_comment').html('留下意見');
					$('#submit_comment').click(function(){initialAjaxCommentForm();$('#commentForm').submit();});
				}
				else if(data.status_code == '4'){
					$('#submit_comment').html('留下意見');
					$('#submit_comment').click(function(){initialAjaxCommentForm();$('#commentForm').submit();});
					
					$.ajax({
						url: '/houseme/showLoginFirstForm',
						type:"POST",
						dataType:"json",
						data:{
							
						},
						success: function(data)
						{	
							$('#loginFirstBox').html(data.html);
							showLoginFirstBox();
							$(".logBtnEmail").click(function(e){
								e.preventDefault();
								CloseLoginFirstForm();
								$.ajax({
									url: '/houseme/showLoginForm',
									type:"POST",
									dataType:"json",
									data:{
										
									},
									success: function(data)
									{	
										$('#loginBox').html(data.html);
										showLoginBox();
										initialLoginForm();
									}
									});
							});
						}
					});
				}
	        }  
	    }; 
	 
	    // bind form using 'ajaxForm' 
	    $('#commentForm').ajaxForm(options); 
	    $('#commentForm').submit();
	}
	else{
		return false;	
	}
    
}

function addVotePhoto(){
	
    if($('.votePhotos').length>=5){
		alert('最多上傳5張照片');
	}
	else{
		var html = '<div class="desc_area"><div class="photo_desc" >圖片說明：</div><div class="photo_desc_input"><input style="width:180px;" name="photo_desc[]"/></div></div><div class="btn1"><input class="votePhotos" type="file" accept="image/*" name="image[]"></div>';

		$('#votePhotosArea').append($(html).hide().fadeIn(2000));
	}
}

function addCommentPhoto(){
	
    if($('.votePhotos').length>=5){
		alert('最多上傳5張照片');
	}
	else{
		var html = '<div class="btn1"><input class="votePhotos" type="file" accept="image/*" name="image[]"></div>';

		$('#votePhotosArea').append($(html).hide().fadeIn(2000));
	}
}

function report_valid_post_email_content(){
	var re = '';

	re  =	"檢舉網址:"+ '%0D';
	re +=	"檢舉原因:"+ '%0D';;
	re +=	'%0D%0D%0D%0D';;
	re +=	"好俬迷感謝您如此重視分享在我們網站上的內容，我們會仔細審核您的檢舉內容。"+ '%0D';
	re +=	"最晚在3天內回信說明處理結果。"+ '%0D%0D';

	re +=	"好俬迷團隊"+ '%0D';
	re +=	"敬上";

	return re;
}

function updateImageSize() {

    $("#tpCont").each(function(){
        var ratio_cont = jQuery(this).width()/jQuery(this).height();
        var $img = jQuery(this).find("img");
        var ratio_img = $img.width()/$img.height();
        if (ratio_cont > ratio_img)
        {
            $img.css({"width": "100%", "height": "auto"});
        }
        else if (ratio_cont < ratio_img)
        {
            //$img.css({"width": "auto", "height": "100%"});
            $img.css({"width": "100%", "height": "auto"});
        }
    });

    $(".PageText").each(function(){
        var ratio_cont = jQuery(this).width()/jQuery(this).height();
        var $img = jQuery(this).find("img");
        var ratio_img = $img.width()/$img.height();
        if (ratio_cont > ratio_img)
        {
            $img.css({"width": "100%", "height": "auto"});
        }
        else if (ratio_cont < ratio_img)
        {
            //$img.css({"width": "auto", "height": "100%"});
            $img.css({"width": "100%", "height": "auto"});
        }
    });
}

function newUploadImage(){
	if($('.uploadIdeaImageField').length>=5){
		alert('最多上傳5張照片');
	}
	else{
		var html = '<div class="uploadIdeaImageField">'+
		'<label for="uploadIdeaImage">&nbsp;</label>'+
		'<div class="uploadIdeaImage"><input type="file" value="" placeholder="" name="upload_image[]" accept="image/*" capture="camera" /><span style="float: right; display: inline-block; margin-top: -22px;"><a href="javascript:;" onclick="deleteUploadImage(this);return false;">[刪除]</a></span></div>'+
		'</div>';

		$('#uploadImageZone').append($(html).hide().fadeIn(2000));
	}
}

function deleteUploadImage(obj){
	if($('.uploadIdeaImageField').length<=1){
		alert('最少上傳1張照片');
	}
	else{
		$(obj).parent().parent().parent('.uploadIdeaImageField').remove();
	}

}

function confirmBeforeSendShare(){
	var r = confirm("請確認您的分享內容:\n\n類別："+$('#post_category').val()+"\n標題："+$('#uploadIdeaExcerpt').val()+"\n描述："+$('#uploadIdeaDesc').val());
	if (r == true) {
	    txt = "You pressed OK!";
	    $('#uploadImageForm').submit();
	} else {
	    txt = "You pressed Cancel!";
	}
}

function confirmBeforeSendShareWithName(){
	var r = confirm("請確認您的分享內容:\n\n類別："+$('#post_category').val()+"\n標題："+$('#uploadIdeaExcerpt').val()+"\n描述："+$('#uploadIdeaDesc').val()+"\n顯示名稱："+$('#uploadIdeaUsername').val());
	if (r == true) {
	    txt = "You pressed OK!";
	    $('#uploadImageForm').submit();
	} else {
	    txt = "You pressed Cancel!";
	}
}

$(document).ready(function () {
    updateImageSize();
    $(window).resize(function() {
        updateImageSize();
    });

/*my page waterfall*/

/*waterfall*/
var paginationArea = "#page-nav";
	var page_to_next_link = "#page-next-link";
	var $container = jQuery('#photoList ul'); //container area
	var $topicContainer = jQuery('#topicList ul'); //container area
	var itemSelector = '#photoList ul li';
	var itemTopicSelector = '.topicIterms';
	//瀑布流
			$container.imagesLoaded( function() {
			   $container.isotope({
                    itemSelector: itemSelector,
                    masonry:{
                    	columnWidth: 10
                    }
                });
			});

           
			$topicContainer.imagesLoaded( function() {
            $topicContainer.isotope({
                    itemSelector: itemTopicSelector,
                    masonry:{
                    	columnWidth: 10
                    }
                });
            });

            /*waterfall filter buttons*/
            $('#filters a').click(function(){
			  var selector = $(this).attr('data-filter');
			  $topicContainer.isotope({ filter: selector });
			  
			  return false;
			});

            var processing = false;
            //console.log('start: '+processing);
            $(window).scroll(function()
			{	
				if (processing || $(paginationArea).length<=0 )return false;//if page nav area not exist ,do not get more data
				if($(document).height() > $(window).height()){
				    if($(window).scrollTop() + $(window).height() >= $(document).height())
				    {
				    	processing=true;
				        $('#infscr-loading').show();
				        $.ajax({
				        url: $(page_to_next_link).attr('href'),
				        type:"GET",
				        dataType: "json",
				        success: function(data)
				        {
				            if(data.nextLink)
				            {
				            	var $newEls = $( data.html );

        						$container.append( $newEls ).isotope( 'appended', $newEls );

				                $(page_to_next_link).attr('href',data.nextLink);
				                setTimeout(function(){processing=false;},700);
				                TweenLite.to($(".btn_memberLike"), 0, {css:{bottom:30,alpha:0}});
								TweenLite.to($(".btn_collect"), 0, {css:{bottom:30,alpha:0}});
								TweenLite.to($(".btn_sharefb"), 0, {css:{bottom:30,alpha:0}});
								
								var N = 0;
								$("#photoList ul li").hover(function(){
									N = $(this).index();
									TweenLite.to($(".btn_memberLike").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
									TweenLite.to($(".btn_collect").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
									TweenLite.to($(".btn_sharefb").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
									TweenLite.to($("#photoList ul li").eq(N).find("span"), 0.3, {css:{alpha:1},ease:Quint.easeOut});
								},function(){
									TweenLite.to($(".btn_memberLike"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
									TweenLite.to($(".btn_collect"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
									TweenLite.to($(".btn_sharefb"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
									TweenLite.to($("#photoList ul li").find("span"), 0.3, {css:{alpha:0},ease:Quint.easeOut});
								});
								$('.btn_collect').click(function(){
									var collect_link = $(this).find('span').html();
									$.ajax({
										url: '/collect/showForm',
										type:"POST",
										dataType:"json",
										data:{
											collect_link: collect_link
										},
										success: function(data)
										{	
											if(data.status_code == '1')
											{
												$('#collectBox').html(data.html);
												showAddCollectForm();	
												initialAddCollectForm();
											}else if(data.status_code == '3'){
											    alert(data.msg);
												//window.location.href = "/houseme/FBlogin";
											}
										}
										});
								});
				                //$('#photoList').css('height', $('#photoList').innerHeight()+'px');
				                $('#infscr-loading').hide();
				            }else
				            {
				            	setTimeout(function(){processing=true;},700);//stop ajax
				            	//$('#infscr-loading').hide();
				                $('#infscr-loading').html('<center>無更多文章</center>');
				            }
				        }
				        });
				    }
				}
			});	



$('.editorListBtn a').click(function(e){
	e.preventDefault();
	var collect_link = $(this).find('span').html();
		$.ajax({
			url: '/collect/showEditCollectForm',
			type:"POST",
			dataType:"json",
			data:{
				current_category: $(this).attr('collect-name')
			},
			success: function(data)
			{	
				if(data.status_code == '1')
				{
					$('#editCollectBox').html(data.html);
					initialEditCollectForm();
					showEditCollectForm();	
				}else if(data.status_code == '3'){
				    alert(data.msg);
					//window.location.href = "/houseme/FBlogin";
				}
			}
			});
});

$('.memberEditor a').click(function(e){
	e.preventDefault();
	var collect_link = $(this).find('span').html();
		$.ajax({
			url: '/auth/showEditUserInfoForm',
			type:"POST",
			dataType:"json",
			data:{
				//current_category: $(this).attr('collect-name')
			},
			success: function(data)
			{	
				if(data.status_code == '1')
				{
					$('#editUserInfoBox').html(data.html);
					initialEditUserInfoForm();
					showEditUserInfoForm();	
				}else if(data.status_code == '3'){
				    alert(data.msg);
					//window.location.href = "/houseme/FBlogin";
				}
			}
			});
});

$('.addMyPhoto a').click(function(e){
	e.preventDefault();
	var collect_link = $(this).find('span').html();
		$.ajax({
			url: '/collect/showUploadIdeaForm',
			type:"POST",
			dataType:"json",
			data:{
				
			},
			success: function(data)
			{	
				if(data.status_code == '1')
				{
					$('#uploadIdeaBox').html(data.html);
					initialUploadIdeaForm();
					showUploadIdeaForm();
					initialAjaxForm();
					
				}else if(data.status_code == '3'){
				    alert(data.msg);
				}
			}
			});
});

$('.uploadShareBtn a').click(function(e){
	e.preventDefault();
	
		$.ajax({
			url: '/collect/showUploadIdeaForm',
			type:"POST",
			dataType:"json",
			data:{
				
			},
			success: function(data)
			{	
				if(data.status_code == '1')
				{
					$('#uploadIdeaBox').html(data.html);
					initialUploadIdeaForm();
					showUploadIdeaForm();
					initialAjaxForm();
					
				}else if(data.status_code == '3'){
				    $.ajax({
						url: '/houseme/showLoginFirstForm',
						type:"POST",
						dataType:"json",
						data:{
							
						},
						success: function(data)
						{	
							$('#loginFirstBox').html(data.html);
							showLoginFirstBox();
							$(".logBtnEmail").click(function(e){
								e.preventDefault();
								CloseLoginFirstForm();
								$.ajax({
									url: '/houseme/showLoginForm',
									type:"POST",
									dataType:"json",
									data:{
										
									},
									success: function(data)
									{	
										$('#loginBox').html(data.html);
										showLoginBox();
										initialLoginForm();
									}
									});
							});
						}
					});
				}
			}
			});
});

/*先拿掉
$('.helpBtn a').click(function(e){
	e.preventDefault();
	
		$.ajax({
			url: '/question/checkLoginStatus',
			type:"POST",
			dataType:"json",
			data:{
				
			},
			success: function(data)
			{	
				if(data.status_code == '1') // login already, redirect to question page
				{
					window.location = "/question";
					
				}else if(data.status_code == '2'){
				    $.ajax({
						url: '/houseme/showLoginFirstForm',
						type:"POST",
						dataType:"json",
						data:{
							
						},
						success: function(data)
						{	
							$('#loginFirstBox').html(data.html);
							showLoginFirstBox();
							$(".logBtnEmail").click(function(e){
								e.preventDefault();
								CloseLoginFirstForm();
								$.ajax({
									url: '/houseme/showLoginForm',
									type:"POST",
									dataType:"json",
									data:{
										
									},
									success: function(data)
									{	
										$('#loginBox').html(data.html);
										showLoginBox();
										initialLoginForm();
									}
									});
							});
						}
					});
				}
			}
			});
});
*/

function initialAjaxForm(){

	var temp;
	var options = { 
        beforeSubmit:  function(){
        	$('#uploadIdeaBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
        },
        dataType:  'json',
        success:  function(data){
        	if(data.status_code == '2'){
				alert(data.msg);
				$('#uploadIdeaBox').html(data.html);
				initialUploadIdeaForm();
				initialAjaxForm();
			}
			else if(data.status_code == '1'){ // upload success
				alert(data.msg);
				location.reload();
			}
			else if(data.status_code == '3'){// form error
				$('#uploadIdeaBox').html(data.html);
				initialUploadIdeaForm();
				initialAjaxForm();
			}else{
				alert(data.msg);
				CloseLoginFrom();	
			}
        }  
 		
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#uploadImageForm').ajaxForm(options); 
}

function initialEditCollectForm(){
	$(".btnCloseEdit").click(function(event){
		event.preventDefault();
		CloseLoginFrom();
	});

	$(".edit_btn_cancel a").click(function(e){
		CloseLoginFrom();
		e.preventDefault();
	});

	$('.edit_btn_collect_send').click(function(event){
			event.preventDefault();
			var temp = $('#editCollectBox').html();
			$.ajax({
				url: '/collect/editCategoryName',
				type:"POST",
				dataType: "json",
				data:{
					new_category_name: $('#collectEditName').val(),
					old_category_name: $('#oldCollectName').val()
				},
				beforeSend:function(){
					
					$('#editCollectBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){
						alert(data.msg);
						CloseLoginFrom();
					}
					else if(data.status_code == true){
						alert(data.msg);
						location.reload();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
						//window.location.href = "/houseme/FBlogin";
					}
					else{
						alert(data.msg);
						CloseLoginFrom();
					}
					 
				}
			});
			
		});
}

function initialEditUserInfoForm(){
	$(".btnCloseEdit").click(function(event){
		event.preventDefault();
		CloseLoginFrom();
	});

	$(".edit_btn_cancel a").click(function(e){
		CloseLoginFrom();
		e.preventDefault();
	});

	$('.edit_btn_userinfo_send').click(function(event){
			event.preventDefault();
			var temp = $('#editUserInfoBox').html();
			$.ajax({
				url: '/auth/editUserInfo',
				type:"POST",
				dataType: "json",
				data:{
					new_username: $('#userinfo_name').val()
				},
				beforeSend:function(){
					
					$('#editUserInfoBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){
						$('#editUserInfoBox').html(temp);
						initialEditUserInfoForm();
						alert(data.msg);
					}
					else if(data.status_code == '1'){
						alert(data.msg);
						location.reload();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
						//window.location.href = "/houseme/FBlogin";
					}
					else{
						alert(data.msg);
						CloseLoginFrom();
					}
					 
				}
			});
			
		});
}

function initialUploadIdeaForm(){
	$(".btnCloseEdit").click(function(event){
		event.preventDefault();
		CloseLoginFrom();
	});

	$(".upload_idea_btn_cancel a").click(function(e){
		CloseLoginFrom();
		e.preventDefault();
	});

	$('#ideaCategory').click(function(){
		if($('#ideaCategoryWrapper').css("display")=='none'){
			$('#ideaCategoryWrapper').show();
		}
		else{
			$('#ideaCategoryWrapper').hide();
		}
	});

	$('#dropdown_arrow').click(function(){
		if($('#ideaCategoryWrapper').css("display")=='none'){
			$('#ideaCategoryWrapper').show();
		}
		else{
			$('#ideaCategoryWrapper').hide();
		}
	});

	$('#ideaCategoryList li').click(function(){
		$('#ideaCategoryWrapper').hide();
		$('#ideaCategory').html($(this).text());
		$('#post_category').val($(this).text());
	});

	$('.edit_btn_collect_send').click(function(event){
			event.preventDefault();
			var temp = $('#editCollectBox').html();
			$.ajax({
				url: '/collect/editCategoryName',
				type:"POST",
				dataType: "json",
				data:{
					new_category_name: $('#collectEditName').val(),
					old_category_name: $('#oldCollectName').val()
				},
				beforeSend:function(){
					
					$('#editCollectBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){
						alert(data.msg);
						CloseLoginFrom();
					}
					else if(data.status_code == '1'){
						alert(data.msg);
						location.reload();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
						//window.location.href = "/houseme/FBlogin";
					}
					else{
						alert(data.msg);
						CloseLoginFrom();
					}
					 
				}
			});
			
		});
}

function initialAddCollectForm(){
		$(".btn_cancel a").click(function(e){
			CloseLoginFrom();
			e.preventDefault();
		});
		$(".btnClose").click(function(e){
			CloseLoginFrom();
			e.preventDefault();
		});

		$('#ideaCategory').click(function(){
			if($('#ideaCategoryWrapper').css("display")=='none'){
				$('#ideaCategoryWrapper').show();
			}
			else{
				$('#ideaCategoryWrapper').hide();
			}
		});

		$('#dropdown_arrow').click(function(){
			if($('#ideaCategoryWrapper').css("display")=='none'){
				$('#ideaCategoryWrapper').show();
			}
			else{
				$('#ideaCategoryWrapper').hide();
			}
		});

		$('#ideaCategoryList li').click(function(){
			$('#ideaCategoryWrapper').hide();
			$('#ideaCategory').html($(this).text());
		});

		$('#createNewCategoryButton').click(function(){
			$.ajax({
				url: '/collect/addCategory',
				type:"POST",
				dataType: "json",
				data:{
					new_category: $('#newCategory').val()
				},
				beforeSend:function(){
					$('#createNewCategoryButton span').html('<img src="/assets/img/input-spinner.gif"/>');
				},
				success: function(data)
				{
					if(data.status_code == '3'){
						alert(data.msg);
						//window.location.href = "/houseme/FBlogin";
					}
					else if(data.status_code == '1'){
						$('#newCategory').val('');
						$('#ideaCategoryList').prepend(data.html);
						$('#ideaCategoryList li').click(function(){
							$('#ideaCategoryWrapper').hide();
							$('#ideaCategory').html($(this).text());
						});
					}
					else if(data.status_code == '4' || data.status_code == '5'){
						alert(data.msg);
					}

					$('#createNewCategoryButton span').html('新增');
				}
			});
		});

		$('.btn_collect_send a').click(function(event){
			event.preventDefault();
			var temp = $('#collectBox').html();
			$.ajax({
				url: '/collect/add',
				type:"POST",
				dataType: "json",
				data:{
					collect_link: $('#collect_link').val(),
					collect_category:$('#ideaCategory').text()
				},
				beforeSend:function(){
					
					$('#collectBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){
						alert(data.msg);
						$('#collectBox').html(temp);
						initialAddCollectForm();
					}
					else if(data.status_code == '1'){
						alert(data.msg);
						CloseLoginFrom();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
					}
					 
				}
			});
			
		});
	}

function initialLoginForm(){

		$(".btn_cancel a").click(function(e){
			CloseLoginFrom();
			e.preventDefault();
		});
		$(".btnClose").click(function(e){
			CloseLoginFrom();
			e.preventDefault();
		});

		$(".register_btn_cancel a").click(function(e){
			CloseLoginFrom();
			e.preventDefault();
		});

		$(".register_link").click(function(e){
			e.preventDefault();
			$.ajax({
				url: '/houseme/showRegisterForm',
				type:"POST",
				dataType:"json",
				data:{
					
				},
				success: function(data)
				{	
					$('#loginBox').html(data.html);
					initialLoginForm();
				}
			});
		});

		$(".forgot_password_link").click(function(e){
			e.preventDefault();
			$.ajax({
				url: '/houseme/showForgotPasswordForm',
				type:"POST",
				dataType:"json",
				data:{
					
				},
				success: function(data)
				{	
					$('#loginBox').html(data.html);
					initialLoginForm();
				}
			});
		});
		/*login*/
		$('.btn_login_send').click(function(event){
			event.preventDefault();
			var temp = $('#loginBox').html();
			
			$.ajax({
				url: '/auth/fe_login',
				type:"POST",
				dataType:"json",
				data:{
					login: $('#email_login').val(),
					password: $('#password_login').val()
				},
				beforeSend:function(){
					
					$('#loginBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){ // error occurred
						//alert(data.msg);
						$('#loginBox').html(data.html);
						initialLoginForm();
					}
					else if(data.status_code == '1'){
						if(data.goto_page != null){
							window.location = data.goto_page;
						}
						else if(data.page_action_event_element != null){
							CloseLoginFrom();
							console.log(data.page_action_event_element);
							$(data.page_action_event_element)[0].click();
						}
						else{
							location.reload();	
						}
						
					}
					else if(data.status_code == '3'){
						alert(data.msg);
					}
					 
				}
			});
			
		});

		/*send again*/
		$('.btn_login_send_again').click(function(event){
			event.preventDefault();
			var temp = $('#loginBox').html();
			
			$.ajax({
				url: '/auth/fe_send_again',
				type:"POST",
				dataType:"json",
				data:{
					email: $('#email_login').val()
				},
				beforeSend:function(){
					
					$('#loginBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){ // error occurred
						//alert(data.msg);
						$('#loginBox').html(data.html);
						initialLoginForm();
					}
					else if(data.status_code == '1'){
						location.reload();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
						location.reload();
					}
					 
				}
			});
			
		});

		/*forgot password*/
		$('.btn_forgot_password_send').click(function(event){
			event.preventDefault();
			var temp = $('#loginBox').html();
			
			$.ajax({
				url: '/auth/fe_forgot_password',
				type:"POST",
				dataType:"json",
				data:{
					login: $('#email_login').val()
				},
				beforeSend:function(){
					
					$('#loginBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){ // error occurred
						//alert(data.msg);
						$('#loginBox').html(data.html);
						initialLoginForm();
					}
					else if(data.status_code == '1'){
						location.reload();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
						location.reload();
					}
					 
				}
			});
			
		});

		$('.register_btn_send').click(function(event){
			event.preventDefault();
			var temp = $('#loginBox').html();
			
			$.ajax({
				url: '/auth/fe_register',
				type:"POST",
				dataType:"json",
				data:{
					username: $('#username_register').val(),
					email: $('#email_register').val(),
					password: $('#password_register').val(),
					confirm_password: $('#confirm_password_register').val()
				},
				beforeSend:function(){
					
					$('#loginBox').html('<div style="margin:0 auto;width:100%;height:100%;"><img src="/assets/img/input-spinner.gif" style="position:absolute;top:50%;left:50%;display:block;"/></div>');
				},
				success: function(data)
				{
					if(data.status_code == '2'){
						$('#loginBox').html(data.html);
						initialLoginForm();
					}
					else if(data.status_code == '1'){
						alert(data.msg);
						CloseLoginFrom();
					}
					else if(data.status_code == '3'){
						alert(data.msg);
					}
					 
				}
			});
		});
}

function BrushBlack(){
		TweenLite.to($("#pleaseLogIn"), 0, {css:{display:"none"}});
		TweenLite.to($("#collectBox"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#collectBox"), 0.5, {alpha:1,ease:Quint.easeOut});
		}});
		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
		}});
	}

	function showAddCollectForm(){
		TweenLite.to($("#collectBox"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#collectBox"), 0.5, {alpha:1,ease:Quint.easeOut});
		}});
		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
		}});
	}

	function showLoginBox(){
		TweenLite.to($("#loginBox"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#loginBox"), 0.5, {alpha:1,ease:Quint.easeOut});
		}});
		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
		}});
	}

	function showEditCollectForm(){
		TweenLite.to($("#editCollectBox"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#editCollectBox"), 0.5, {alpha:1,ease:Quint.easeOut});
		}});
		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
		}});
	}

	function showEditUserInfoForm(){
		TweenLite.to($("#editUserInfoBox"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#editUserInfoBox"), 0.5, {alpha:1,ease:Quint.easeOut});
		}});
		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
		}});
	}

	function showUploadIdeaForm(){
		TweenLite.to($("#uploadIdeaBox"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#uploadIdeaBox"), 0.5, {alpha:1,ease:Quint.easeOut});
		}});
		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
		}});	
	}

	function CloseLoginFrom(){
		TweenLite.to($("#brushBlack"), 0.5, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#brushBlack"), 0, {css:{display:"none"}});
		}});
		TweenLite.to($("#collectBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#collectBox"), 0, {css:{display:"none"}});
		}});
		TweenLite.to($("#editCollectBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#editCollectBox"), 0, {css:{display:"none"}});
		}});
		TweenLite.to($("#editUserInfoBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#editUserInfoBox"), 0, {css:{display:"none"}});
		}});
		TweenLite.to($("#loginBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#loginBox"), 0, {css:{display:"none"}});
		}});

		TweenLite.to($("#loginFirstBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#loginFirstBox"), 0, {css:{display:"none"}});
		}});

		TweenLite.to($("#uploadIdeaBox"), 0, {alpha:0,ease:Quint.easeOut,onComplete:function(){
			TweenLite.to($("#uploadIdeaBox"), 0, {css:{display:"none"}});
		}});

		TweenLite.to($("#logInTitle a"), 0.5, {css:{left:0},ease:Quint.easeOut});
		TweenLite.to($("#enterForm"), 0.5, {css:{left:0},ease:Quint.easeOut});
		TweenLite.to($("#forgetForm"), 0.5, {css:{left:300},ease:Quint.easeOut});
	}


	$('.cycle-slideshow').cycle({
    	speed: 600,
    	manualSpeed: 100
	});
	
	 jQuery('#photoList ul').imagesLoaded(function(){
                jQuery('#photoList ul').masonry({
                    itemSelector: '#photoList ul li',
                    columnWidth: 10
                });
            });
            
	
	//---------------------------------------*****
	//=====主選單
	//---------------------------------------*****
	/*
	$("#nav ul li").hover(function(e){
		var N = $(this).index();
		TweenLite.to($("#nav ul li a").eq(N), 0.5, {css:{backgroundPosition:"top"},ease:Quint.easeOut});
	},function(e){
		TweenLite.to($("#nav ul li a"), 0.5, {css:{backgroundPosition:"bottom"},ease:Quint.easeOut});
	});
*	*/
	//---------------------------------------*****
	//=====我的收藏
	//---------------------------------------*****
	$(".myTag").hover(function(){
		TweenLite.to($(".myTag a"), 0.5, {css:{backgroundPosition:"top"},ease:Quint.easeOut});
	},function(){
		TweenLite.to($(".myTag a"), 0.5, {css:{backgroundPosition:"bottom"},ease:Quint.easeOut});
	});
	//---------------------------------------*****
	//=====登入會員，FB及Email登入
	//---------------------------------------*****
	/*
	$(".logBtnFb").click(function(e){
		e.preventDefault();
		BrushBlack();
	});
	*/
	
	
	$(".btnClose").click(function(e){
		CloseLoginFrom();
		e.preventDefault();
	});

	
	$("#brushBlack").click(function(e){
		CloseLoginFrom();
		e.preventDefault();
		TweenLite.to($("#pleaseLogIn"), 0, {css:{display:"none"}});
	});
	
	$(".btn_Forget").click(function(e){
		TweenLite.to($("#logInTitle a"), 0.5, {css:{left:-95},ease:Quint.easeOut});
		TweenLite.to($("#enterForm"), 0.5, {css:{left:-300},ease:Quint.easeOut});
		TweenLite.to($("#forgetForm"), 0.5, {css:{left:0},ease:Quint.easeOut});
		e.preventDefault();
	});
	
	$(".btn_delForget").click(function(e){
		TweenLite.to($("#logInTitle a"), 0.5, {css:{left:0},ease:Quint.easeOut});
		TweenLite.to($("#enterForm"), 0.5, {css:{left:0},ease:Quint.easeOut});
		TweenLite.to($("#forgetForm"), 0.5, {css:{left:300},ease:Quint.easeOut});
		e.preventDefault();
	});
	
	//---------------------------------------*****
	//=====編輯帳號，創造我的俬迷本，上傳我的俬分享
	//---------------------------------------*****
	//目前三個視窗都設定display:none全都放在html的滿上面的
	
	//---------------------------------------*****
	//=====PhotoList member按鍵操作
	//---------------------------------------*****
	//初始值先將三顆按鈕藏起
	TweenLite.to($(".btn_memberLike"), 0, {css:{bottom:30,alpha:0}});
	TweenLite.to($(".btn_collect"), 0, {css:{bottom:30,alpha:0}});
	TweenLite.to($(".btn_sharefb"), 0, {css:{bottom:30,alpha:0}});
	
	var N = 0;
	$("#photoList ul li").hover(function(){
		N = $(this).index();
		TweenLite.to($(".btn_memberLike").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
		//TweenLite.to($(".btn_collect").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
		TweenLite.to($(".btn_sharefb").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
		TweenLite.to($("#photoList ul li").eq(N).find("span"), 0.3, {css:{alpha:1},ease:Quint.easeOut});
	},function(){
		TweenLite.to($(".btn_memberLike"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
		//TweenLite.to($(".btn_collect"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
		TweenLite.to($(".btn_sharefb"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
		TweenLite.to($("#photoList ul li").find("span"), 0.3, {css:{alpha:0},ease:Quint.easeOut});
	});

	$("#topicList ul li").hover(function(){
		N = $(this).index();
		TweenLite.to($(".btn_memberLike").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
		//TweenLite.to($(".btn_collect").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
		TweenLite.to($(".btn_sharefb").eq(N), 0.3, {css:{bottom:60,alpha:1},ease:Quint.easeOut});
		TweenLite.to($("#topicList ul li").eq(N).find("span"), 0.3, {css:{alpha:1},ease:Quint.easeOut});
	},function(){
		TweenLite.to($(".btn_memberLike"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
		//TweenLite.to($(".btn_collect"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
		TweenLite.to($(".btn_sharefb"), 0.3, {css:{bottom:30,alpha:0},ease:Quint.easeOut});
		TweenLite.to($("#topicList ul li").find("span"), 0.3, {css:{alpha:0},ease:Quint.easeOut});
	});
	
	//未登入會員時的提示視意
	$("#photoList ul li").click(function(e){
//		TweenLite.to($("#brushBlack"), 0, {css:{display:"block"},onComplete:function(){
//			TweenLite.to($("#brushBlack"), 0.5, {alpha:0.85,ease:Quint.easeOut});
//		}});
//			TweenLite.to($("#pleaseLogIn"), 0, {css:{display:"block"}});
	});

	$(".btn_memberLike").hover(function(){
		TweenLite.to($(".btn_memberLike").eq(N), 0.5, {css:{backgroundPosition:"top left"},ease:Quint.easeOut});
	},function(){
		TweenLite.to($(".btn_memberLike").eq(N), 0.5, {css:{backgroundPosition:"bottom left"},ease:Quint.easeOut});
	});
	
	$(".btn_collect").hover(function(){
		TweenLite.to($(".btn_collect").eq(N), 0.5, {css:{backgroundPosition:"top left"},ease:Quint.easeOut});
	},function(){
		TweenLite.to($(".btn_collect").eq(N), 0.5, {css:{backgroundPosition:"bottom left"},ease:Quint.easeOut});
	});
	
	$(".btn_sharefb").hover(function(){
		TweenLite.to($(".btn_sharefb").eq(N), 0.5, {css:{backgroundPosition:"top left"},ease:Quint.easeOut});
	},function(){
		TweenLite.to($(".btn_sharefb").eq(N), 0.5, {css:{backgroundPosition:"bottom left"},ease:Quint.easeOut});
	});
	
//  這裡只是示意當按了喜歡之後的樣子~~詳細因為要記錄每一個單獨的再麻煩程式大哥嘍謝謝~目前只有一個記錄~所以如果有東西被按了，另一個會要按兩次才能改回ML的布林
	var ML = true;
	$(".btn_memberLike").click(function(e){
		//console.log(N);
		if(ML == true){
			TweenLite.to($(".btn_memberLike").eq(N), 0, {css:{width:80,textIndent:0,backgroundPosition:"top left"}});
			TweenLite.to($(".btn_collect").eq(N), 0.3, {css:{marginLeft:125},ease:Quint.easeOut});
			TweenLite.to($(".btn_sharefb").eq(N), 0.3, {css:{marginLeft:160},ease:Quint.easeOut});
			ML = false;
		}else{
			TweenLite.to($(".btn_memberLike").eq(N), 0, {css:{width:0,textIndent:-9999}});
			TweenLite.to($(".btn_collect").eq(N), 0.3, {css:{marginLeft:45},ease:Quint.easeOut});
			TweenLite.to($(".btn_sharefb").eq(N), 0.3, {css:{marginLeft:80},ease:Quint.easeOut});
			ML = true;
		}
		e.preventDefault();
	});

	
	$('.btn_collect').click(function(){
		var collect_link = $(this).find('span').html();
		$.ajax({
			url: '/collect/showForm',
			type:"POST",
			dataType:"json",
			data:{
				collect_link: collect_link
			},
			success: function(data)
			{	
				if(data.status_code == '1')
				{
					$('#collectBox').html(data.html);
					showAddCollectForm();	
					initialAddCollectForm();
				}else if(data.status_code == '3'){
				    alert(data.msg);
					//window.location.href = "/houseme/FBlogin";
				}
			}
			});
	});

	$('.myTag a').click(function(e){
		e.preventDefault();
		$.ajax({
			url: '/houseme/check_my_status',
			type:"POST",
			dataType:"json",
			success: function(data)
			{	
				if(data.status_code == '1') //login already
				{
					window.location.href = data.mylink;
				}else if(data.status_code == '2'){ // not login yet
				    alert(data.msg);
				}
			}
			});
	});

	$('.pageBtn_collect').click(function(){
		var collect_link = $(this).find('span').html();
		$.ajax({
			url: '/collect/showForm',
			type:"POST",
			dataType:"json",
			data:{
				collect_link: collect_link
			},
			success: function(data)
			{	
				if(data.status_code == '1')
				{
					$('#collectBox').html(data.html);
					showAddCollectForm();	
					initialAddCollectForm();
				}else if(data.status_code == '3'){
				    alert(data.msg);
					//window.location.href = "/houseme/FBlogin";
				}
			}
			});
	});

	$(".logBtnEmail").click(function(e){
		e.preventDefault();
		$.ajax({
			url: '/houseme/showLoginForm',
			type:"POST",
			dataType:"json",
			data:{
				
			},
			success: function(data)
			{	
				$('#loginBox').html(data.html);
				showLoginBox();
				initialLoginForm();
			}
			});
	});

	

});


